﻿using Business.FlowOperation;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WF_Business;

public partial class Office_TaskBackAnyway : PageBase
{
    WorkFlowHandle TaskBack = new WorkFlowHandle();
    string rstep = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        rstep = Request["step"];
        if (!IsPostBack)
        {
            ToBind();
        }
    }
    private void ToBind()
    {
        string iid = Request["iid"];
        gv.DataSource = TaskBack.GetTaskByiid(iid);
        gv.DataBind();
    }
    protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DropDownList ddlBackStep = (DropDownList)e.Row.FindControl("ddlBackStep");
            string iid = Request["iid"];
            DataTable dt = TaskBack.GetBackStepByiid(iid, UserId, rstep);
            //因为有USERID有重复的情况，导致value相同，现在后面加|数字来区分
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dt.Rows[i]["userid"] = dt.Rows[i]["userid"].ToString() + "|" + i.ToString();
            }
            ddlBackStep.DataSource = dt;
            ddlBackStep.DataTextField = "经办人";
            ddlBackStep.DataValueField = "userid";
            ddlBackStep.DataBind();
        }
    }

    protected void lbtnBack_Click(object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)gv.Rows[0].Cells[4].FindControl("ddlBackStep");
        if (ddl.Items.Count > 0)
        {
            //因为有USERID有重复的情况，导致value相同，现在后面加|数字来区分，现在把|去掉
            string oldUserID = ddl.SelectedValue.Substring(0, ddl.SelectedValue.IndexOf("|"));

            string remark = txtRemark.Text;
            string iid = Request["iid"];
            long wiid = Convert.ToInt64(Request["wiid"]);

            WorkItem workItem = new WorkItem();
            if (workItem.Untread(wiid, remark))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "ret", "<script>returnOk();</script>");
            }
            else
            {
                labMsg.Text = "业务回退失败！";
            }
        }
    }
}